home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / tde3.zip / TDEASM.C < prev    next >
C/C++ Source or Header  |  1993-06-05  |  7KB  |  205 lines

  1. /*
  2.  * The DTE 5.1 editor used a big text buffer for editing a file.  The big
  3.  * text buffer holds an image of a file pretty much as it appears on
  4.  * disk.  In that big buffer, '\0' was used to delimit the files.  In TDE
  5.  * versions 2.10 and less, a big text buffer was also used, but ^Z was used
  6.  * instead of '\0' to delimit files.  A double linked list is used in TDE 2.2
  7.  * to hold text.
  8.  *
  9.  * With these functions written in assembly, this editor is fairly fast.
  10.  * I feel the need for speed.
  11.  *
  12.  * New editor name:  TDE, the Thomson-Davis Editor.
  13.  * Author:           Frank Davis
  14.  * Date:             June 5, 1991, version 1.0
  15.  * Date:             July 29, 1991, version 1.1
  16.  * Date:             October 5, 1991, version 1.2
  17.  * Date:             January 20, 1992, version 1.3
  18.  * Date:             February 17, 1992, version 1.4
  19.  * Date:             April 1, 1992, version 1.5
  20.  * Date:             June 5, 1992, version 2.0
  21.  * Date:             October 31, 1992, version 2.1
  22.  * Date:             April 1, 1993, version 2.2
  23.  * Date:             June 5, 1993, version 3.0
  24.  *
  25.  * This modification of Douglas Thomson's code is released into the
  26.  * public domain, Frank Davis.  You may distribute it freely.
  27.  */
  28.  
  29. #include "tdestr.h"
  30. #include "common.h"
  31. #include "tdefunc.h"
  32.  
  33.  
  34. /*
  35.  * Name:    ptoul - pointer to unsigned long
  36.  * Purpose: convert a far pointer to unsigned long integer
  37.  * Date:    June 5, 1991
  38.  * Passed:  s:  a far pointer
  39.  * Notes:   combine the offset and segment like so:
  40.  *                offset       0000
  41.  *                segment   + 0000
  42.  *                          =======
  43.  *                            00000
  44.  *          result is returned in dx:ax
  45.  */
  46. unsigned long ptoul( void far *s )
  47. {
  48.    ASSEMBLE {
  49.         mov     ax, WORD PTR s          /* ax = OFFSET of s */
  50.         mov     dx, WORD PTR s+2        /* dx = SEGMENT of s */
  51.         mov     bx, dx          /* put copy of segment in bx */
  52.         mov     cl, 12          /* cl = decimal 12 - shift hi word 3 hex digits */
  53.         shr     dx, cl          /* convert to 'real segment' */
  54.         mov     cl, 4           /* cl = 4  - shift hi word 1 hex digit left */
  55.         shl     bx, cl          /* shift bx - to add 3 digits of seg to 4 of off */
  56.         add     ax, bx          /* add low part of segment to offset */
  57.         adc     dx, 0           /* if carry, bump to next 'real' segment */
  58.    }
  59. }
  60.  
  61.  
  62. /*
  63.  * Name:    tabout
  64.  * Purpose: Expand tabs in display line
  65.  * Date:    October 31, 1992
  66.  * Passed:  s:  string pointer
  67.  *          len:  pointer to current length of string
  68.  * Notes:   Expand tabs in the display line according to current tab.
  69.  *          If eol display is on, let's display tabs, too.
  70.  */
  71. text_ptr tabout( text_ptr s, int *len )
  72. {
  73. text_ptr to;
  74. int space;
  75. int col;
  76. int i;
  77. int tab_size;
  78. int show_tab;
  79. int tab_len;
  80.  
  81.  
  82.    tab_size = mode.ptab_size;
  83.    show_tab = mode.show_eol;
  84.    to  = (text_ptr)g_status.tabout_buff;
  85.    i = tab_len  = *len;
  86.  
  87.    ASSEMBLE {
  88.         push    si
  89.         push    di
  90.         push    ds
  91.         push    es
  92.  
  93.         mov     bx, WORD PTR tab_size   /* keep tab_size in bx */
  94.         xor     cx, cx                  /* keep col in cx */
  95.  
  96.         mov     di, WORD PTR to
  97.         mov     ax, WORD PTR to+2
  98.         mov     es, ax                  /* es:di == to or the destination */
  99.         mov     si, WORD PTR s
  100.         mov     ax, WORD PTR s+2
  101.         mov     ds, ax                  /* ds:si == s or the source */
  102.    }
  103. top:
  104.  
  105.    ASSEMBLE {
  106.         cmp     cx, MAX_LINE_LENGTH     /* are at end of tabout buffer? */
  107.         jge     get_out
  108.  
  109.         cmp     WORD PTR i, 0           /* are at end of string? */
  110.         jle     get_out
  111.  
  112.         lodsb                           /* al == BYTE PTR ds:si */
  113.         cmp     al, 0x09                /* is this a tab character? */
  114.         je      expand_tab
  115.  
  116.         stosb                           /* store character in es:di inc di */
  117.         inc     cx                      /* increment col counter */
  118.         dec     WORD PTR i              /* decrement string counter */
  119.         jmp     SHORT top
  120.    }
  121. expand_tab:
  122.  
  123.    ASSEMBLE {
  124.         mov     ax, cx
  125.         xor     dx, dx                  /* set up dx:ax for IDIV */
  126.         IDIV    bx                      /* col % tab_size */
  127.         mov     ax, bx                  /* put tab_size in bx */
  128.         sub     ax, dx                  /* ax = tab_size - (col % tab_size) */
  129.         mov     dx, ax                  /* put ax in dx */
  130.         add     cx, ax                  /* col += space */
  131.         cmp     cx, MAX_LINE_LENGTH     /* is col > MAX_LINE_LENGTH? */
  132.         jge     get_out                 /* yes, get out */
  133.         mov     ax, ' '                 /* save blank character in ax */
  134.         cmp     WORD PTR show_tab, 0    /* was show_tab flag set? */
  135.         je      do_the_tab
  136.         mov     ax, 0x09                /* put tab character in ax */
  137.    }
  138. do_the_tab:
  139.  
  140.    ASSEMBLE {
  141.         stosb                           /* store in es:di and incr di */
  142.         dec     dx
  143.         cmp     dx, 0                   /* any spaces left to fill? */
  144.         jle     end_of_space            /* no, get another character */
  145.         add     WORD PTR tab_len, dx    /* add spaces to string length */
  146.         mov     ax, ' '                 /* save blank character in ax */
  147.    }
  148. space_fill:
  149.  
  150.    ASSEMBLE {
  151.         cmp     dx, 0                   /* any spaces left to fill? */
  152.         jle     end_of_space            /* no, get another character */
  153.         stosb                           /* store ' ' in es:di and incr di */
  154.         dec     dx                      /* space-- */
  155.         jmp     SHORT space_fill        /* fill space */
  156.   }
  157. end_of_space:
  158.  
  159.    ASSEMBLE {
  160.         dec     WORD PTR i
  161.         jmp     SHORT top
  162.    }
  163. get_out:
  164.  
  165.    ASSEMBLE {
  166.         pop     es
  167.         pop     ds
  168.         pop     di
  169.         pop     si
  170.    }
  171.    if (tab_len > MAX_LINE_LENGTH)
  172.       tab_len = MAX_LINE_LENGTH;
  173.    *len = g_status.tabout_buff_len = tab_len;
  174.    return( (text_ptr)g_status.tabout_buff );
  175.  
  176. /*
  177.    tab_size = mode.ptab_size;
  178.    show_tab = mode.show_eol;
  179.    to  = g_status.tabout_buff;
  180.    i = tab_len  = *len;
  181.    for (col=0; col < (MAX_LINE_LENGTH - (tab_size+1)) &&  i > 0; s++, i--) {
  182.       if (*s != '\t') {
  183.          *to++ = *s;
  184.          ++col;
  185.       } else {
  186.          space = tab_size - (col % tab_size);
  187.          col += space;
  188.          space--;
  189.          if (space > 0)
  190.             tab_len += space;
  191.          if (show_tab)
  192.             *to++ = '\t';
  193.          else
  194.             *to++ = ' ';
  195.          for (; space > 0; space--)
  196.             *to++ = ' ';
  197.       }
  198.    }
  199.    if (tab_len > MAX_LINE_LENGTH)
  200.       tab_len = MAX_LINE_LENGTH;
  201.    *len = g_status.tabout_buff_len = tab_len;
  202.    return( (text_ptr)g_status.tabout_buff );
  203. */
  204. }
  205.